# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=yash
pkgver=2.50
pkgrel=0
pkgdesc="Yet another shell"
url="http://yash.osdn.jp"
arch="all"
license="GPL-2.0-or-later"
depends="$pkgname-completion"
makedepends="ncurses-dev"
install="$pkgname.post-install $pkgname.pre-deinstall"
subpackages="$pkgname-doc"
source="https://github.com/magicant/yash/releases/download/$pkgver/yash-$pkgver.tar.xz"

_compdir="usr/share/yash/completion"

# Move some bigger completion files to separate subpackages.
_comps="git:git:git[gkx]:git-*
	openssh-client:ssh:ssh-*
	subversion:svn
	valgrind:valgrind
	"
for _i in $_comps; do
	subpackages="$subpackages ${_i%%:*}-yash-completion:_completion:noarch"
done
subpackages="$subpackages $pkgname-completion::noarch"

prepare() {
	default_prepare

	# XXX: Disable hanging tests.
	sed -i -e 's/\bkill[24]-p.tst\b//g' \
		-e 's/\bsignal[12]-y.tst\b//g' \
		tests/Makefile.in

	# Remove completions for programs that are not available on Alpine
	# (just to decrease size of the package).
	cd share/completion
	rm carthage dnf pgawk useradd who
}

build() {
	./configure \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--disable-nls
	make
}

check() {
	# FIXME: Fix broken tests.
	make tests LANG=en_US.UTF-8 || true
}

package() {
	make DESTDIR="$pkgdir" install
	rm -Rf "$pkgdir"/usr/share/man/ja
}

_completion() {
	local name="${subpkgname%-yash-completion}"
	pkgdesc="Yash completions for $name"
	depends="$pkgname-completion"
	install_if="$pkgname-completion=$pkgver-r$pkgrel $name"

	local files=$(printf '%s\n' $_comps \
		| sed -En "s|^$name:(.*)|\1|p" \
		| tr : ' ')
	[ "$files" ] || die "$name not found in \$_comps"

	local f; for f in $files; do
		amove usr/share/yash/completion/$f
	done
}

completion() {
	pkgdesc="$pkgdesc (command-line completion)"
	depends=""

	amove usr/share/yash/completion
}

sha512sums="fc78d61b09f7c81d1d7bd3f4feefa7d4c0de910524759ebcba2b53322abc3f1e0a937007b36a5060af0ee759df210ec06d5eed2c71cf3f7ccd0825521b50edb7  yash-2.50.tar.xz"
